from time import sleep

from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By

from BlogSystemAutoTest.Common.Utils import BlogDriver
from BlogSystemAutoTest.testTask.BlogLogin import Alert


#测试博客列表的自动化测试用例

#定义一个测试列表的类对象

class BlogList:
    url=""
    driver=""
    def __init__(self):
        self.url="http://47.99.68.28:8888/blog/blog_html/blog_home.html"
        self.driver=BlogDriver.driver

    #验证登陆状态下的博客列表
    def getBlogListNormal(self):
        self.driver.find_element(By.CSS_SELECTOR,'#bloglist > div:nth-child(1) > h2')
        self.driver.find_element(By.CSS_SELECTOR,"#bloglist > div:nth-child(1) > p")
        self.driver.find_element(By.CSS_SELECTOR,"#bloglist > div:nth-child(1) > a").click()
        self.driver.find_element(By.CSS_SELECTOR,"#back")
        self.driver.find_element(By.CSS_SELECTOR,"#delete")


    def getBlogListABnormal(self):
        self.driver.get(self.url)
        try:
            self.driver.find_element(By.CSS_SELECTOR, '#bloglist > div:nth-child(1) > h2')
        except NoSuchElementException:
            BlogDriver.getScreenShort()

